<!-- /*
 * @Author: 谢力 843926058@qq.com
 * @Date:   2019-11-06
 * @Last Modified by:   谢力
 * @Last Modified time: 2019-11-07
 */ -->
<template>
    <div class="ui-mode-box flex-col">
        <div class="mt-tab-title">可用积分<i>{{totalNum|formatText}}</i>分</div>
        <div class="mt-tab-inner relative flex1">
            <div class="ui-mode-box body" ref="scroll">
                <div class="relative" v-if="list&&list.length">
                    <div class="item flex-row align-stretch"
                        :key="`score-${i}`"
                        v-for="(item,i) in list">
                        <div class="box flex1">
                            <p class="flex-row align-between-row">
                                <span>{{dictionary.score_type[item.score_type]||'-'}}</span>
                                <span :class="[item.consume_score==0?'black':item.consume_score>0?'green':'red']">{{item.score_remark|formatText}}</span>
                            </p>
                            <p class="flex-row align-between-row gray">
                                <span>{{item.time_consume|formatText}}</span>
                                <span class="black">{{item.consume_score|formatText}}积分</span>
                            </p>
                        </div>
                    </div>
                    <div v-if="isScrolling" class="flex1 flex-row align-center scrolling-content relative">
                        <span class="icon">
                            <bsx-loading master-background="rgba(0,0,0,0)" box-background="rgba(0,0,0,0)" :size="35" :show-text="false"></bsx-loading>
                        </span>
                        <span class="text">努力加载中...</span>
                    </div>
                    <div v-else-if="isLoadEnded" class="flex1 flex-row align-center scrolling-content relative">已经到底啦~~</div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import mixinCommon from '@/views/content/mixins/common';
import mixinRequest from '@/views/content/mixins/request';
import mixinList from '@/views/content/mixins/list';
export default {
    data(){
        return {
        };
    },
    mixins:[
        mixinCommon,
        mixinRequest,
        mixinList
    ],
    props:{
        totalNum:''
    },
    computed:{
    },
    watch:{
        resourceLoaded:{
            handler(flag){
                flag&&this.$nextTick(this.init);
            },
            immediate:true
        }
    },
    created(){
    },
    mounted(){
    },
    methods:{
        // 初始化
        init(){
            this.getListInfo({
                flag:true,
                page:0
            });
        },
        // 获取列表数据
        getListInfo({flag,page,callback}){
            this.getShopInfo().then(()=>{
                this.getPageInfo({
                    name:'book.score',
                    param:{
                        invoke_method:'public_page_4m_score_list',
                        pre_db_para_begin_idx:page*this.pageSize,
                        pre_db_para_length_4_list:this.pageSize,
                        score_type_in:'1,2,3,4,5,6,7,8,9,10',
                        is_online:0,
                        buyer_id:this.public_user_info.id_public_user_info,
                        pre_db_para_order_by_para:'time_consume DESC',
                    }
                }).then(({result,response})=>{
                    if(result.page_content&&result.page_content.length){
                        this.list.push(...result.page_content.slice(0,this.pageSize));
                        this.currentPage=page;
                        if(result.page_content.length<this.pageSize){
                            this.isLoadEnded=true;
                        }else if((this.currentPage+1)*this.pageSize>=result.result_num){
                            this.isLoadEnded=true;
                        };
                        callback&&callback();
                    }else{
                        if(flag){
                            this.showResult('没有查询到相关数据');
                        }else{
                            this.showToast('没有查询到相关数据',false);
                        };
                        callback&&callback();
                    };
                }).catch(({msg})=>{
                    if(!flag){
                        this.showToast(msg,false);
                    };
                    callback&&callback();
                });
            }).catch(({msg})=>{
                if(!flag){
                    this.showToast(msg,false);
                };
                callback&&callback();
            });
        },
        // 获取当前用户信息
        getShopInfo(){
            return new Promise((resolve,reject)=>{
                let public_agent_info=this.$store.state.global.public_agent_info,
                    public_user_info=this.$store.state.global.public_user_info;
                if(public_agent_info&&public_user_info){
                    this.public_agent_info=public_agent_info;
                    this.public_user_info=public_user_info;
                    document.title=this.public_agent_info.application_name;
                    resolve({});
                }else{
                    this.$http.post({
                        name:'my',
                        data:{
                            invoke_method:'user_and_shop_info'
                        },
                        loading:{
                            enabled:false
                        }
                    }).then(({result,response})=>{
                        this.public_agent_info=result.public_agent_info||{};
                        this.public_user_info=result.public_user_info||{};
                        document.title=this.public_agent_info.application_name;
                        this.setState({
                            key:'public_agent_info',
                            value:this.public_agent_info
                        });
                        this.setState({
                            key:'public_user_info',
                            value:this.public_user_info
                        });
                        resolve({result,response});
                    }).catch(({msg})=>{
                        reject({msg});
                    });
                };
            });
        },
        // 加载失败刷新
        handleRefresh(){
            this.init();
        }
    },
    components:{
    },
    beforeDestroy(){
    }
}
</script>
<style lang="less" scoped>
</style>
